package com.minglead.springboot.platform.sys.web;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.minglead.springboot.common.crud.BaseController;
import com.minglead.springboot.platform.sys.entity.DesktopPlug;
import com.minglead.springboot.platform.sys.entity.DesktopPlugConfig;
import com.minglead.springboot.platform.sys.entity.Role;
import com.minglead.springboot.platform.sys.entity.User;
import com.minglead.springboot.platform.sys.service.DesktopPlugConfigService;
import com.minglead.springboot.platform.sys.utils.UserUtils;
/**
 * 桌面控制器
 * @author clz
 * @date 2017-8-29
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/desktop")
public class DesktopController extends BaseController {	
	
	@Autowired
	private DesktopPlugConfigService desktopPlugConfigService;
	
	@RequestMapping(value = { "index", "" })
	public String index(HttpServletRequest request, HttpServletResponse response) {			
		User user =UserUtils.getUser();
		Role role = user.getRole();	
/*		List<DesktopPlugConfig> plugList = desktopPlugConfigService.getListByRoleId(role.getId());*/
		//项目简单，不使用配置方式了，现在直接写死，如果是招生办(recruitDept)，就看桌面、其他角色不给看任何东西
		List<DesktopPlugConfig> plugList = new ArrayList<DesktopPlugConfig>();
		//一个人属于多个角色的话，这个可能会出现问题，后期再看怎么修正
		if("recruitDept".equals(role.getCode())||user.isAdmin()){
			DesktopPlugConfig d = new DesktopPlugConfig();
			d.setId("id_1");
			d.setPlugId("plugConfig_1");
			d.setRoleId(role.getId());
			DesktopPlug desktopPlug = new DesktopPlug();
			desktopPlug.setCss("width: 98%;margin:3px;");
			desktopPlug.setId("plug_1");
			desktopPlug.setUrl("/stu/stuDesktop/recruitDept");
			d.setDesktopPlug(desktopPlug);
			plugList.add(d);
			
		}
		request.setAttribute("plugList", plugList);
		return "modules/sys/desktop";
	}	
}